<?php

namespace app\service;

/**
 * 抽奖算法概括
 */
class LotteryCollect
{
    public static function get_rand($proArr)
    {
        $result = '';

        // 概率数组的总概率精度
        $proSum = array_sum($proArr);

        // 概率数组循环 id => 概率
        foreach ($proArr as $key => $proCur) {
            $randNum = mt_rand(1, $proSum);
            if ($randNum <= $proCur) {
                $result = $key;
                break;
            } else {
                $proSum -= $proCur;
            }
        }
        unset ($proArr);
        return $result;
    }

    public static function get_rand2() {
        $totalNum = 100; //总份数
        $randNum = mt_rand(1, $totalNum);
        $result = '';
        switch (true) {
            case $randNum == 1:
                $data = (new \app\model\UserModel)->getCount();
                if ($data) {
                    $result = 1;
                    break;
                }
            case $randNum > 1 && $randNum <= 100:
                $result = 2;
                break;
            default:
                $result = 3;
                break;
        }
    }
}